$(function () {
    Time();
    load();
})

//返回
function fh() {
    localStorage.removeItem("chaSH_ID");
    location.href = "../../li_meng/CPSCGXShengHe.html";
}

//时间
function Time() {
    var time = new Date();
    var y = time.getFullYear();
    var mon = time.getMonth() + 1; //0-11
    var d = time.getDate();
    var h = time.getHours();
    var m = time.getMinutes();
    var s = time.getSeconds();
    $("#date").val(y + "-" + mon + "-" + d + " " + h + ":" + m + ":" + s);
}

//表单
function load() {
    let user = JSON.parse(localStorage.getItem("user"));
    $("#rname").val(user.rname);
    let mdesignprocedureKaiShiSH = JSON.parse(localStorage.getItem("mdesignprocedureKaiShiSH"));
    //设计单编号
    $("#designid").text(mdesignprocedureKaiShiSH.designid);
    $("#sjdID").text(mdesignprocedureKaiShiSH.designid);
    //设计人
    $("#designer").text(mdesignprocedureKaiShiSH.designer);
    //产品编号
    $("#productid").text(mdesignprocedureKaiShiSH.productid);
    //产品名称
    $("#productname").text(mdesignprocedureKaiShiSH.productname);
    //总工时
    $("#costpricesum").text(mdesignprocedureKaiShiSH.costpricesum);
    //设计要求
    $("#proceduredescribe").text(mdesignprocedureKaiShiSH.proceduredescribe);
    $("#modulecostpricesum").text(mdesignprocedureKaiShiSH.modulecostpricesum);

    $.post("/Mdesignproceduredetails.do/ChaById", {id: mdesignprocedureKaiShiSH.id}, function (sdata) {
        console.log(sdata)
        let str = " <tr >\n" +
            "           <th>序号</th>\n" +
            "           <th>工序名称</th>\n" +
            "           <th>工序编号</th>\n" +
            "           <th>描述</th>\n" +
            "           <th>工时数</th>\n" +
            "           <th>工时成本小计(元)</th>\n" +
            "           <th>物料成本小计(元)</th>\n" +
            "           <th>审核</th>\n" +
            "       </tr>\n";

        $.each(sdata, function (index, item) {
            let s= JSON.stringify(item)
            str +=
                "  <tr>\n" +
                "      <td>" + item.detailsnumber + "</td>\n" +
                "      <td>" + item.procedurename + "</td>\n" +
                "      <td>" + item.procedureid + "</td>\n" +
                "      <td>" + item.proceduredescribe + "</td>\n" +
                "      <td>" + item.labourhouramount + "</td>\n" +
                "      <td>" + item.costprice + "</td>\n" +
                "      <td>" + item.modulesubtotal + "</td>\n" +
                "      <th><input type='button' value='审核' onclick='Cha(" + s + ")'></th>\n" +
                "  </tr>";
        })
        $("#tableAdd").html(str);
    })
}

//提交数据
function Submit() {
    let mdesignprocedureKaiShiSH = JSON.parse(localStorage.getItem("mdesignprocedureKaiShiSH"));
    let mdesignprocedure = {
        designmoduletag: $("[name='zt']:checked").val(),
        checksuggestion: $("#checksuggestion").val(),
        id: mdesignprocedureKaiShiSH.id
    };
    let mdList = JSON.stringify(mdesignprocedure);
    $.post("/Mdesignprocedure.do/LiMengMdesignprocedureSHZT", {mdList: mdList, dfID: mdesignprocedureKaiShiSH.productid}, function (sd) {
        $("#tishi").text("审核成功！")
        $("#tishi").css("color", "lime")
        $("#staticBackdrop").modal("show");
    })
}

//提交后跳页面
function hh() {
  localStorage.removeItem("mdesignprocedureKaiShiSH");
    location.href = "../../li_meng/mdesignprocedureSH.html";
}

function Cha(op) {
    $("#XQModal").modal("show");
    $("#gxName").text(op.procedurename);
    $("#djrName").text(op.register);
    $("#djsjDate").text(op.registertime);

    let sstr = " <tr >\n" +
        "           <th>序号</th>\n" +
        "           <th>物料名称</th>\n" +
        "           <th>物料编号</th>\n" +
        "           <th>描述</th>\n" +
        "           <th>本工序数量</th>\n" +
        "           <th>单位</th>\n" +
        "           <th>单价(元)</th>\n" +
        "           <th>小计(元)</th>\n" +
        "       </tr>\n";
    $.post("/Mdesignproceduremoduledetails.do/limengMdesignproceduremoduledetailsSHCha", {id: op.id}, function (sdate) {
        $.each(sdate, function (index, item) {
            sstr += "  <tr>\n" +
                "      <td>" + item.detailsnumber + "</td>\n" +
                "      <td>" + item.productname + "</td>\n" +
                "      <td>" + item.productid + "</td>\n" +
                "      <td>" + item.productdescribe + "</td>\n" +
                "      <td>" + item.amount + "</td>\n" +
                "      <td>" + item.amountunit + "</td>\n" +
                "      <td>" + item.costprice + "</td>\n" +
                "      <td>" + item.subtotal + "</td>\n" +
                "  </tr>";
        })
        $("#tm01").html(sstr);
    })

}



